﻿using PGMHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeamRein
{
    public class ReinforceInfo
    {
        /// <summary>
        /// 配筋信息
        /// </summary>
        private List<double> reinforceList { set; get; }

        /// <summary>
        /// 数据数量
        /// </summary>
        public int Count
        {
            get
            {
                return this.reinforceList.Count;
            }
        }

        /// <summary>
        /// 获得值
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public double this [int index]
        {
            get
            {
                return this.reinforceList[index];
            }
            set
            {
                this.reinforceList[index] = value;
            }
        }

        /// <summary>
        /// 构件信息
        /// </summary>
        /// <param name="strList"></param>
        public void SetBeamInfo(List<string> strList)
        {
            //获得属性
            for (int i = 0; i < strList.Count - 1; i++)
                this.reinforceList.Add(Convert.ToDouble(strList[i + 1]));
        }

        /// <summary>
        /// 楼层信息
        /// </summary>
        /// <param name="strList"></param>
        public void SetStoreyInfo(string str)
        {
            //拆分语句
            var strList = WilsonHelper.SplitStr(str);
            //获得属性
            for (int i = 0; i < strList.Count - 1; i++)
                this.reinforceList.Add(Convert.ToDouble(strList[i + 1]));
            //插入小计
            this.reinforceList.Insert((int)DataEnum.SubSum, 0);
        }

        /// <summary>
        /// 求和
        /// </summary>
        /// <param name="reinInfo"></param>
        public void Add(ReinforceInfo reinInfo)
        {
            //小计之前
            for (int i = 0; i < (int)DataEnum.SubSum; i++)
                this.reinforceList[i] += reinInfo[i] * reinInfo[(int)DataEnum.Count];
            //小计之后
            for (int i = (int)(DataEnum.SubSum + 1); i < Math.Min(this.Count, reinInfo.Count); i++)
                this.reinforceList[i] += reinInfo[i];
        }

        /// <summary>
        /// 添加值
        /// </summary>
        /// <param name="data"></param>
        /// <param name="reinList"></param>
        public static void ListToData(GridViewDatas data, List<ReinforceInfo> reinList)
        {
            //输出统计信息
            Action<DataEnum> addColumn = dataEnum =>
            {
                //值
                var valueList = (from v in reinList select v[(int)dataEnum]).ToList();
                data.Add(new GridViewColumn(valueList, titleName: dataEnum.ToString(), demical: 2));
            };
            //添加数据
            for (int i = 0; i < GlobalParam.BeamReinforceCount; i++)
                addColumn((DataEnum)i);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ReinforceInfo()
        {
            this.reinforceList = new List<double>();
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ReinforceInfo(int Count) : this()
        {
            for (int i = 0; i < Count; i++) this.reinforceList.Add(0);
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        public ReinforceInfo(ReinforceInfo reinInfo) : this()
        {
            reinInfo.reinforceList.ForEach(rein => this.reinforceList.Add(rein));

        }
    }
}
